{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 结果文件命名规则\n",
    "\n",
    "`result_模型文件名_空个数.txt`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['result_model_346_split2_3_0.997754.h5_22.txt',\n",
       " 'result_model_346_split2_4_150.h5_36.txt',\n",
       " 'result_model_l2\\xe5\\x8a\\xa0\\xe5\\xb1\\x82\\xe7\\x94\\x9f\\xe6\\x88\\x90\\xe5\\x99\\xa82_0.997656.h5_42.txt']"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import glob\n",
    "import numpy as np\n",
    "from collections import Counter\n",
    "\n",
    "glob.glob('result_model*.txt')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 融合规则\n",
    "\n",
    "对所有数据进行次数统计，先去掉空，然后取最高次数的结果。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def fun(x):\n",
    "    c = Counter(x)\n",
    "    c[' '] = 0\n",
    "    return c.most_common()[0][0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "ss = [open(fname, 'r').read().split('\\n') for fname in glob.glob('result_model*.txt')]\n",
    "s = np.array(ss).T\n",
    "with open('result.txt', 'w') as f:\n",
    "    f.write('\\n'.join(map(fun, s)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
